package com.tanglongan.designPattern.dp09_decorator.demo99;

public class GenericClient {

    /**
     * 抽象组件
     */
    static abstract class Component {
        public abstract void operation();
    }

    /**
     * 具体组件
     */
    static class ConcreateComponent extends Component {
        @Override
        public void operation() {
            System.out.println("处理业务逻辑");
        }
    }

    /**
     * 抽象装饰器
     */
    static abstract class Decorator extends Component {
        protected Component component;

        public Decorator(Component compoent) {
            this.component = compoent;
        }

        public void operation() {
            component.operation();
        }
    }

    /**
     * 具体的装饰器
     */
    static class ConcreteDecorator extends Decorator {
        public ConcreteDecorator(Component component) {
            super(component);
        }

        // 在调用父类的operation方法之前调用需要执行的逻辑
        private void operationFirst() {
        }

        // 在调用父类的operation方法之后调用需要执行的逻辑
        private void operationLast() {
        }

        public void operation() {
            operationFirst();
            super.operation();
            operationLast();
        }

    }
}
